<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui">

    <h:form id="DetalleventaListForm">

        <p:panel header="#{myBundle.ListDetalleventaTitle}">
            <p:contextMenu id="DetalleventaDataTableContextMenu" for="datalist">  
                <p:menuitem value="#{myBundle.Create}" onclick="document.getElementById('DetalleventaListForm:createButton').click();" icon="ui-icon-plus"/>
                <p:menuitem value="#{myBundle.View}" onclick="document.getElementById('DetalleventaListForm:viewButton').click();" icon="ui-icon-search"/>
                <p:menuitem value="#{myBundle.Edit}" onclick="document.getElementById('DetalleventaListForm:editButton').click();" icon="ui-icon-pencil"/>
                <p:menuitem value="#{myBundle.Delete}" onclick="document.getElementById('DetalleventaListForm:deleteButton').click();" icon="ui-icon-trash"/>
                <p:separator/>
                <p:menuitem value="#{myBundle.DetalleventaMenuItem_codventa}" icon="ui-icon-search"  actionListener="#{detalleventaController.prepareCodventa}" update=":VentaViewForm" oncomplete="VentaViewDialog.show()" disabled="#{empty detalleventaController.selected.codventa}"/>  
                <p:menuitem value="#{myBundle.DetalleventaMenuItem_codproducto}" icon="ui-icon-search"  actionListener="#{detalleventaController.prepareCodproducto}" update=":ProductoViewForm" oncomplete="ProductoViewDialog.show()" disabled="#{empty detalleventaController.selected.codproducto}"/>  
            </p:contextMenu>
            <p:dataTable id="datalist"
                         value="#{detalleventaController.items}"
                         var="item"
                         rowKey="#{item.codigo}"
                         paginator="true"
                         rows="10"
                         rowsPerPageTemplate="10,20,30,40,50"
                         selectionMode="single"
                         selection="#{detalleventaController.selected}">

                <p:ajax event="rowSelect"   update=":DetalleventaListForm:createButton :DetalleventaListForm:viewButton :DetalleventaListForm:editButton :DetalleventaListForm:deleteButton :DetalleventaListForm:DetalleventaDataTableContextMenu" listener="#{detalleventaController.resetParents}"/>
                <p:ajax event="rowUnselect" update=":DetalleventaListForm:createButton :DetalleventaListForm:viewButton :DetalleventaListForm:editButton :DetalleventaListForm:deleteButton :DetalleventaListForm:DetalleventaDataTableContextMenu" listener="#{detalleventaController.resetParents}"/>
                <p:ajax event="rowDblselect" onsuccess="document.getElementById('DetalleventaListForm:viewButton').click();"/>

                <p:column sortBy="#{item.codigo}" filterBy="#{item.codigo}">
                    <f:facet name="header">
                        <h:outputText value="#{myBundle.ListDetalleventaTitle_codigo}"/>
                    </f:facet>
                    <h:outputText value="#{item.codigo}"/>
                </p:column>


                <p:column sortBy="#{item.cantidad}" filterBy="#{item.cantidad}">
                    <f:facet name="header">
                        <h:outputText value="#{myBundle.ListDetalleventaTitle_cantidad}"/>
                    </f:facet>
                    <h:outputText value="#{item.cantidad}"/>
                </p:column>


                <p:column sortBy="#{item.codventa.codigo}" filterBy="#{item.codventa.codigo}">
                    <f:facet name="header">
                        <h:outputText value="#{myBundle.ListDetalleventaTitle_codventa}"/>
                    </f:facet>
                    <h:outputText value="#{item.codventa.codigo}"/>
                </p:column>


                <p:column sortBy="#{item.codproducto.codigo}" filterBy="#{item.codproducto.codigo}">
                    <f:facet name="header">
                        <h:outputText value="#{myBundle.ListDetalleventaTitle_codproducto}"/>
                    </f:facet>
                    <h:outputText value="#{item.codproducto.codigo}"/>
                </p:column>


            </p:dataTable>

            <p:commandButton id="createButton"                             icon="ui-icon-plus"   value="#{myBundle.Create}" actionListener="#{detalleventaController.prepareCreate}" update=":DetalleventaCreateForm" oncomplete="DetalleventaCreateDialog.show()"/>
            <p:commandButton id="viewButton"   style="visibility: hidden;" icon="ui-icon-search" value="#{myBundle.View}" update=":DetalleventaViewForm" oncomplete="DetalleventaViewDialog.show()" disabled="#{empty detalleventaController.selected}"/>
            <p:commandButton id="editButton"   style="visibility: hidden;" icon="ui-icon-pencil" value="#{myBundle.Edit}" update=":DetalleventaEditForm" oncomplete="DetalleventaEditDialog.show()" disabled="#{empty detalleventaController.selected}"/>
            <p:commandButton id="deleteButton" style="visibility: hidden;" icon="ui-icon-trash"  value="#{myBundle.Delete}" actionListener="#{detalleventaController.delete}" update=":growl,datalist" disabled="#{empty detalleventaController.selected}">
                <p:confirm header="#{myBundle.ConfirmationHeader}" message="#{myBundle.ConfirmDeleteMessage}" icon="ui-icon-alert"/>
            </p:commandButton>

        </p:panel>
        <ui:include src="/confirmation.xhtml"/>
    </h:form>

</ui:composition>